package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import neusoft.yuejian_11.activity.AllPostDatilActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.PostBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.PostListViewHolder;

import com.squareup.picasso.Picasso;

import java.util.List;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by NEUSOFT on 2017/9/28.
 */

public class PostListAdapter extends BaseListAdapter {
    public PostListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_allpost,parent,false);
        PostListViewHolder holder=new PostListViewHolder(itemView);
        return holder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        PostListViewHolder postListViewHolder=(PostListViewHolder) holder;
        final PostBean postBean = (PostBean)data.get(position);

        final String postTitle =postBean.getP_title();
        String postclub=postBean.getC_name();
        String postpeople=postBean.getU_name();
        String posttime=postBean.getP_createtime();
        final int  postId=postBean.getP_id();
        //图片
        String pic = BASE_URI+"pphoto/"+postBean.getP_pic();
        String pic1 = BASE_URI+"photo/"+postBean.getU_pic();
        Picasso.with(context)
                .load(pic)
                .placeholder(R.drawable.ic_cook_holder)
                .error(R.drawable.ic_cook_holder_error)
                .into(PostListViewHolder.imageView);
        Picasso.with(context)
                .load(pic1)
                .placeholder(R.drawable.ic_cook_holder)
                .error(R.drawable.ic_cook_holder_error)
                .into(PostListViewHolder.imageViewtx);
        postListViewHolder.posttitleView.setText(postTitle);
        postListViewHolder.postclubView.setText(postclub);
        postListViewHolder.postpersonView.setText(postpeople);
        postListViewHolder.posttimeView.setText(posttime);
        postListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(context, AllPostDatilActivity.class);
                intent.putExtra("p_id",postId);
                context.startActivity(intent);
            }
        });
    }


}
